const { getOne } = require('../utils/dbTools')
const { getMemberInfoById } = require('./member')
const tableName = 'appointment'

/**
 * 获取预约详情
 * @param {number} id 预约id
 * 
*/
const getAppointDetail = async (id) => {
    if (!id) return false
    const result = await getOne(tableName, { id })
    // 查询医生信息
    const doctor = await getMemberInfoById(result.doctor_id);
    if (doctor) {
        doctor.tags = doctor.tags ? doctor.tags.split(',') : doctor.tags
        result.doctor = doctor;
    }
    const patient = await getMemberInfoById(result.patient_id);
    // 查询病人信息
    if (patient) {
        result.patient = patient;
    }
    return result
}

module.exports = {
    getAppointDetail
}
